﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "TypeDeletedDlg.h"
#include "IFamilyTypeInfo.h"
#include "IFamilyLoadOptions.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"
using namespace gcmp;

int static dpeth = 0;

TypeDeletedDlg::TypeDeletedDlg(const std::wstring& familyTypeName, int instanceCount, const std::vector<const gcmp::IFamilyTypeInfo*>& familyTypeInfo)
    : m_familyTypeName(familyTypeName)
    , m_familyTypeInfo(familyTypeInfo)
{
    m_ui.setupUi(this);
    connect(m_ui.ReplaceTypeButton, SIGNAL(clicked()), this, SLOT(OnReplaceTypeClick()));
    connect(m_ui.DeleteTypeButton, SIGNAL(clicked()), this, SLOT(OnDeleteTypeClick()));

    std::wstring text = gcmp::StringUtil::FormatWString(GBMP_TR(L"无法在载入的构件中找到 %s 类型(有%i个实例)"), familyTypeName.c_str(), instanceCount);
    m_ui.TypeDetetedLabel->setText(QString::fromStdWString(text));

    FOR_EACH(pFamilyType, m_familyTypeInfo)
    {
        m_ui.TypeSelectComboBox->addItem(QString::fromStdWString(pFamilyType->GetName()));
    }
    m_loadOptions = gcmp::LoadOptions::Cancel;
}

TypeDeletedDlg::~TypeDeletedDlg()
{

}

gcmp::UniIdentity TypeDeletedDlg::GetReplaceTypeUid() const
{
    return m_replaceTypeUid;
}

gcmp::LoadOptions TypeDeletedDlg::GetLoadOption() const
{
    return m_loadOptions;
}

void TypeDeletedDlg::OnReplaceTypeClick()
{
    m_replaceTypeUid = m_familyTypeInfo[m_ui.TypeSelectComboBox->currentIndex()]->GetFamilyTypeUid();
    m_loadOptions = LoadOptions::Overwrite;
    QDialog::accept();
}

void TypeDeletedDlg::OnDeleteTypeClick()
{
    m_replaceTypeUid = gcmp::UniIdentity::InvalidUid;
    m_loadOptions = LoadOptions::Delete;
    QDialog::accept();
}

void TypeDeletedDlg::closeEvent(QCloseEvent* event)
{
    m_loadOptions = LoadOptions::Cancel;
    QDialog::accept();
}